<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0">
    <title>window.structuredClone 深拷贝</title>
    <style>

    </style>
  </head>

  <body>
    <script>
      function Person(name, age, props) {
        this.name = name;
        this.age = age;
        this.props = props;
        // aaa可被克隆
        this.aaa = null;
        // ccc可被克隆
        this.ccc = undefined;
        // 报错：无法克隆SayHello
        // this.SayHello = function () {
        //   return "Hello!";
        // };
      }
      // 原型对象上的属性不会被克隆
      Person.prototype.gender = 1;
      const p = new Person('sote', 22, { a: 1, b: 2, c: 3 });
      console.log(p);
      // 不会拷贝原型上的属性，只会拷贝自身的属性和方法，主要用于替代JSON.parse(JSON.stringify(obj))
      const p2 = window.structuredClone(p);
      console.log(p2);
      console.log(p.props === p2.props);
    </script>
  </body>

</html>
